﻿using System;
using BizElements.Core;

namespace BizElements.BusinessLayer
{
    /// <summary>Dummy actor that has all permissions. The class implements singleton design pattern and new instances of this class cannot be created.
    /// Use <see cref="SuperUser.Instance"/> to access global read-only instance.</summary>
    [Serializable]
    public sealed class SuperUser : IActor
    {
        #region Configuration.

        /// <summary>Gets or sets the value returned by <see cref="Id"/> property. Default is <b>0</b>.</summary>
        public static object IdConfiguration = 0;
        
        /// <summary>Gets or sets the value returned by <see cref="Name"/> property. Default is <b>SuperUser</b>.</summary>
        public static string NameConfiguration = "SuperUser";

        /// <summary>Gets or sets the value returned by <see cref="PrimaryUnit"/> property. Default is <b>0</b>.</summary>
        public static object PrimaryUnitConfiguration = 0;

        /// <summary>Gets or sets the value returned by <see cref="Organization"/> property. Default is <b>0</b>.</summary>
        public static object OrganizationIdConfiguration = 0;

        /// <summary>Gets or sets the value returned by <see cref="SessionId"/> property. Default is <b>null</b>.</summary>
        public static object SessionIdConfiguration = null;

        #endregion

        #region Singleton Instance property.

        /// <summary>Gets singleton object.</summary>
        public static readonly SuperUser Instance = new SuperUser();

        private SuperUser()
        {
        }

        #endregion

        #region IActor Members.

        /// <summary>Returns <b>true</b>.</summary>
        /// <param name="actionId">Any value.</param>
        /// <returns><b>true</b></returns>
        public bool HasPermission(object actionId)
        {
            return true;
        }

        /// <summary>Returns the value configured in <see cref="IdConfiguration"/> static property. Default is <b>0</b>.</summary>
        public object Id
        {
            get { return IdConfiguration; }
        }

        /// <summary>Returns <b>true</b>.</summary>
        /// <param name="unit">Any value.</param>
        /// <returns><b>true</b></returns>
        public bool IsInUnit(object unit)
        {
            return true;
        }

        /// <summary>Returns the value configured in <see cref="NameConfiguration"/> static property. Default is <b>SuperUser</b>.</summary>
        public string Name
        {
            get { return NameConfiguration; }
        }

        /// <summary>Returns the value configured in <see cref="PrimaryUnitConfiguration"/> static property. Default is <b>0</b>.</summary>
        public object PrimaryUnit
        {
            get { return PrimaryUnitConfiguration; }
        }

        /// <summary>Returns an array that contains a single value: <see cref="PrimaryUnit"/>.</summary>
        public object[] AllUnits
        {
            get { return new object[] { PrimaryUnit }; }
        }

        /// <summary>Returns empty collection.</summary>
        public IPropertyCollection<string> ExtendedProperties
        {
            get { return new PropertyCollection<string>(true); }
        }

        /// <summary>Returns the value configured in <see cref="OrganizationIdConfiguration"/> static property. Default is <b>0</b>.</summary>
        public object Organization
        {
            get { return OrganizationIdConfiguration; }
        }

        /// <summary>Returns the value configured in <see cref="SessionIdConfiguration"/> static property. Default is <b>null</b>.</summary>
        public object SessionId
        {
            get { return SessionIdConfiguration; }
        }

        #endregion
    }
}
